package cn.me.alphamq.nameserver.event.spi.listener.service;

import cn.me.alphamq.common.entity.resp.ListAllTopicInfoResp;
import cn.me.alphamq.common.enumeration.EventCodeEnum;
import cn.me.alphamq.common.event.Listener;
import cn.me.alphamq.common.msg.TcpMsg;
import cn.me.alphamq.nameserver.cache.Container;
import cn.me.alphamq.nameserver.event.model.service.ListAllTopicInfoEvent;
import com.alibaba.fastjson2.JSON;

/**
 * 控制台列举所有 topic 信息的事件的监听器
 *
 * @author f
 */
public class ListAllTopicInfoListener implements Listener<ListAllTopicInfoEvent> {

    @Override
    public void onReceive(ListAllTopicInfoEvent event) throws Exception {
        event.getCtx().writeAndFlush(new TcpMsg(EventCodeEnum.LIST_ALL_TOPIC_INFO_RESP,
                JSON.toJSONBytes(new ListAllTopicInfoResp(
                        event.getListAllTopicInfoReq().getMsgId(),
                        Container.getCommitLogTopicModelList(),
                        Container.getConsumeQueueOffsetModel()
                ))));
    }
}
